<template>
  <div>
    <div class="aui-content aui-margin-b-15">
      <ul class="aui-list aui-media-list">
        <van-pull-refresh v-model="announce_data.refreshing" @refresh="fnLoadMore" :disabled="disabled">
            <van-list
              v-model="announce_data.loading"
              :finished="announce_data.finished"
              :finished-text="text"
              @load="initData"
            >
            <li class="aui-list-item aui-bg-f aui-padded-10 van-hairline--bottom" v-for="(item, index) in announce_data.items" @click="fnOpenArticle(item.id)" v-cloak>
                <div class="aui-media-list-item-inner">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-text">
                            <div class="aui-ftn14 aui-text-3" v-text="item.title"></div>
                        </div>
                        <div class="aui-ftn12 aui-text-6 aui-padded-t-5" v-text="item.createtime">
                        </div>
                    </div>
                </div>
            </li>
          </van-list>
        </van-pull-refresh>
      </ul>
      <div v-if="announce_data.isTotal && announce_data.items.length == 0" v-cloak>
          <div class="no-data aui-text-center aui-text-9">
              <i class="iconfont icon-lujing1161"></i>
              <div class="aui-ftn16">
                  空空如也~
              </div>
          </div>
      </div>
  </div>
  </div>
</template>

<script>
  import List from '../../../service/announce.js'
  export default {
    data () {
      return {
        text: '',
        announce_data: {
          loading: false,
          finished: false,
          refreshing: false,
          items: [],
          page: 0,
          limit: 20
        },
		loading: false,
		disabled: false
      }
    },
	mounted() {
		window.addEventListener('scroll', this.handleScroll, true)
	},
	beforeDestroy() {
		window.removeEventListener('scroll', this.handleScroll, true)
	},
    methods: {
		handleScroll () {
			this.disabled = this.utils.handleScroll()
		},
		initData: function() {
			if (this.announce_data.loading && !this.announce_data.finished && !this.loading) {
				this.loading = true
				this.announce_data.page++
				List.fnGetDataList({p: this.announce_data.page, n: this.announce_data.limit, isLoading: true}).then(res => {
					this.loading = false
					// 加载状态结束
					this.announce_data.loading = false;
					if (res && res.status) {
						this.announce_data.items = this.announce_data.items.concat(res.data)
					} else {
						this.announce_data.finished = true;
						if (this.announce_data.items.length > 0) this.text = '没有更多了'
					}
				})
			}
		},
		fnLoadMore: function() {
			this.announce_data.finished = false
			this.announce_data.loading = true
			this.announce_data.page = 0
			this.text = ''
			this.announce_data.items = []
			this.announce_data.refreshing = false;
			this.initData()
		},
		fnOpenArticle: function(id) {
			this.utils.fnOpenCommon(this, {name: 'notice_detail', params: {id: id}, query: {type: 1}})
		}
    }
  }
</script>

<style>
</style>
